// Store object infos
var actionHistory =(function(){
	var currentObject;
	var currentObjects;
	var isClone = false;
	var historys = [];
	var OLDC_History = function(OLDC_Object,actionType){
		this.oldc_object = OLDC_Object;
		this.object = OLDC_Object.object;
		this.angle = OLDC_Object.angle;
		this.zoomRatio = OLDC_Object.zoomRatio;
		this.height = OLDC_Object.height;
		this.width = OLDC_Object.width;
		this.theight = OLDC_Object.theight;
		this.twidth = OLDC_Object.twidth;
		this.X = OLDC_Object.X;
		this.Y = OLDC_Object.Y;
		this.center = OLDC_Object.center;
		this.currentX = OLDC_Object.currentX;
		this.currentY = OLDC_Object.currentY;
		this.iconX = OLDC_Object.iconX;
		this.iconY = OLDC_Object.iconY;
		this.iconZoomRatio = OLDC_Object.iconZoomRatio;
		this.actionType = actionType;
		this.left_x = OLDC_Object.left_x;
		this.left_y = OLDC_Object.left_y;
		this.right_x = OLDC_Object.right_x;
		this.right_y = OLDC_Object.right_y;
		this.memo = OLDC_Object.memo;
	}
	var markClone = function () {
		isClone = true;
	}
	var clear = function () {
		currentObjects = null;
		currentObject = null;
		isClone = false;
	}
	var revocation = function(){
		if (historys.length > 0) {
			svgCanvas.clearSelection();
			var objects = historys.pop();
			objects.forEach(function (obj) {
				if (obj.actionType == 'new') {
					svgCanvas.historyRemoveObject( obj.object.id );
				}else if(obj.actionType == 'move'){
					var currentObj = svgCanvas.list[obj.object.id];
					svgCanvas.transform(obj.object.id, (obj.center[0] - currentObj.center[0]), (obj.center[1] - currentObj.center[1]));
					svgCanvas.list[obj.object.id].currentX = obj.currentX;
					svgCanvas.list[obj.object.id].currentY = obj.currentY;
					svgCanvas.list[obj.object.id].center = obj.center;
				}else if(obj.actionType == 'size'){
					svgCanvas.list[ obj.object.id ].zoomRatio = obj.zoomRatio;
					svgCanvas.transform( obj.object.id );
				}else if(obj.actionType == 'angle'){
					svgCanvas.list[ obj.object.id ].angle = obj.angle;
					svgCanvas.transform( obj.object.id );
				}else if(obj.actionType == 'delete'){
					var objectID = obj.object.id;
					svgCanvas.loadObjects(obj.oldc_object);
				}
				console.log(obj);
			});
		}

	}
	var push = function(OLDC_Object,actionType){
		if (!currentObjects) {
			currentObjects = [];
		}
		if (actionType == 'move') {
			if (historys.length > 0) {
				var lastObjects = historys[historys.length - 1];
				for (var i = 0; i < lastObjects.length; i++) {
					var lastObject = lastObjects[i];
					if (lastObject.actionType == 'move'&&OLDC_Object.object.id==lastObject.object.id) {
						if (OLDC_Object.currentX == lastObject.currentX && OLDC_Object.currentY == lastObject.currentY) {
							return;
						}
					}
				}
			}
		}
		var currentObject = new OLDC_History(OLDC_Object, actionType);
		currentObjects.push(currentObject);
		historys.push(currentObjects);
		//if()
	}
	var pushHistorys = function(){
		if (currentObjects) {
			historys.push(currentObjects);
		}
	}
	var obj = {
		OLDC_History:OLDC_History,
		currentObject:currentObject,
		historys:historys,
		push:push,
		pushHistorys:pushHistorys,
		markClone:markClone,
		clear:clear,
		revocation:revocation
	}

	return obj;

})();